package com.ruoyi.web.controller.system;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.FlowerCategory;
import com.ruoyi.system.service.IFlowerCategoryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 花卉分类管理Controller
 * 
 * @author lwb
 * @date 2024-12-26
 */
@RestController
@RequestMapping("/system/category")
public class FlowerCategoryController extends BaseController
{
    @Resource
    private IFlowerCategoryService flowerCategoryService;

    /**
     * 查询花卉分类管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:category:list')")
    @GetMapping("/list")
    public TableDataInfo list(FlowerCategory flowerCategory)
    {
        startPage();
        List<FlowerCategory> list = flowerCategoryService.selectFlowerCategoryList(flowerCategory);
        return getDataTable(list);
    }
    /**
     * 花卉分类管理列表
     */
    @GetMapping("/listAll")
    public List<FlowerCategory> listAll()
    {
        return flowerCategoryService.listAll();
    }

    /**
     * 导出花卉分类管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:category:export')")
    @Log(title = "花卉分类管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FlowerCategory flowerCategory)
    {
        List<FlowerCategory> list = flowerCategoryService.selectFlowerCategoryList(flowerCategory);
        ExcelUtil<FlowerCategory> util = new ExcelUtil<FlowerCategory>(FlowerCategory.class);
        util.exportExcel(response, list, "花卉分类管理数据");
    }

    /**
     * 获取花卉分类管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:category:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(flowerCategoryService.selectFlowerCategoryById(id));
    }

    /**
     * 新增花卉分类管理
     */
    @PreAuthorize("@ss.hasPermi('system:category:add')")
    @Log(title = "花卉分类管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FlowerCategory flowerCategory)
    {
        return toAjax(flowerCategoryService.insertFlowerCategory(flowerCategory));
    }

    /**
     * 修改花卉分类管理
     */
    @PreAuthorize("@ss.hasPermi('system:category:edit')")
    @Log(title = "花卉分类管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FlowerCategory flowerCategory)
    {
        return toAjax(flowerCategoryService.updateFlowerCategory(flowerCategory));
    }

    /**
     * 删除花卉分类管理
     */
    @PreAuthorize("@ss.hasPermi('system:category:remove')")
    @Log(title = "花卉分类管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(flowerCategoryService.deleteFlowerCategoryByIds(ids));
    }
}
